﻿using System.Windows;
using RentAWorker.Management.Infrastructure;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using System.Windows.Input;
using System.Linq;
using Microsoft.Practices.Composite.Presentation.Commands;
using Microsoft.Practices.Composite.Regions;

namespace RentAWorker.Management.Shell
{
    /// <summary>
    /// Interaction logic for Shell.xaml
    /// </summary>
    public partial class Shell : Window, IShellView, IExtendableShell
    {
        public Shell()
        {
            InitializeComponent();
        }

        public void ShowView()
        {
            this.Show();
        }

        #region IExtendableShell Members

        public void AddToolBarItem(object view, string text, ImageSource image, ICommand command)
        {
            Button b = new Button()
            {
                Content = text,
                Tag = view,
                Command = command
            };

            ToolBar.SetOverflowMode(b, OverflowMode.Never);

            this.MainToolbar.Items.Add(b);
        }

        public void RemoveToolBarItems(object identifier)
        {
            var items = from Control t in this.MainToolbar.Items
                        where t.Tag != null && t.Tag.Equals(identifier)
                        select t;

            while (items.Count() > 0)
            {
                var item = items.First();
                this.MainToolbar.Items.Remove(item);
            }
        }

        public void ShowStatusBarText(string text)
        {
            ((StatusBarItem)this.Statusbar.Items[0]).Content = text;
        }

        #endregion

        public ICommand CloseTabCommand { get; set; }
    }
}
